// COLUMNS
function SDX_Columns(_RootObject)
{
 this.RootObject = _RootObject ;
 this.Columns=new Array();
 this.Column=Column;
 this.InsertColumn=InsertColumn;
 this.GetHTMLOutPut = GetHTMLOutPut ;
 this.GetHTMLOutPuts = GetHTMLOutPuts;
 this.GetColumnsDisplayInTable = GetColumnsDisplayInTable ;
 this.GetVisibleColumns = GetVisibleColumns ;
 this.Initialize=Initialize;
 this.VisibleColumns=null;
 this.GetColumnsXML = GetColumnsXML
 // Column
 function Column(_RootObject, _Columns, _ID, _Field, _Key, _Header, _Visible, _Class)
 {
  this.RootObject = _RootObject ;
  this.Columns = _Columns ;
  this.ID = _ID ;
  this.Key = _Key ;
  this.Field = _Field ;
  this.Header = _Header ;
  this.Visible = _Visible ;
  this.DataType = "" ;
  this.ColumnName = "" ;
  this.AllowDBNull = true ; // NOT IMPLEMENTED
  this.AutoIncrement = false ; // NOT IMPLEMENTED
  this.AutoIncrementStep = 1 ; // NOT IMPLEMENTED
  this.DefaultValue = _Field.DefaultValue ;
  this.ReadOnly = false ; // NOT IMPLEMENTED
  this.Unique = false ; // NOT IMPLEMENTED
  this.LastAutoIncrementID = 0 ;
  this.Class = _Class;
  this.GetHTMLOutPut = GetHTMLOutPut ;
  this.GetHTMLOutPutX = GetHTMLOutPutX ;
  function GetEvalObjectString()
  {
   return this.ParentObject.GetEvalObjectString() + "_Columns" + ID ;
  }
  function GetHTMLOutPut(_Table)
  {
   var sortImageHTML = "" ;
   if( (_Table.Navigator.SortRotation == 1) && (_Table.Navigator.SortColumnIndex == this.ID) )
   {
    sortImageHTML = "<img height=15 width=15 src=\"" + this.RootObject.ResourcePath + "images\\sp_btnDownArrow.gif\">"
   }
   else if( (_Table.Navigator.SortRotation == 0) && (_Table.Navigator.SortColumnIndex == this.ID) )
   {
    sortImageHTML = "<img height=15 width=15 src=\"" + this.RootObject.ResourcePath + "images\\sp_btnUpArrow.gif\">"
   }
   var html = "" ;
   var dragHTML = "<table><tr><td width=100% class=SDX_Column_Header>" + this.Header + "</td></tr></table>" ;
   html += "<td style='cursor:default' " + this.RootObject.Styles.GetStyleHTML(this.RootObject.Styles.HeaderStyle) +
           (this.RootObject.AllowGroupBy==true?" onmousedown=\"" + this.RootObject.Name + ".Events.dragStart(event, 'userimg','" + dragHTML + "'," + _Table.GetEvalObjectString() + ".RootObject.Columns.Columns[" + this.ID + "])\"":"") +
           (this.RootObject.AllowSorting==true?" onclick=\"" + _Table.GetEvalObjectString() + ".Navigator.Sort(" + this.ID + ")\"":"") +
           "><table><tr><td width=100% " + this.RootObject.Styles.GetStyleHTML(this.RootObject.Styles.HeaderStyle) + ">" + this.Header + "</td><td width=10>" + sortImageHTML + "</td></tr></table></td>";
   return html;
  }
  function GetHTMLOutPutX(isFirstColumn)
  {
   var sortImageHTML = "" ;
   var html = "" ;
   var dragHTML = "<table><tr><td width=100% class=SDX_Column_Header>" + this.Header + "</td></tr></table>" ;
   var colspan = "1" ;
   if(isFirstColumn)
   {
    colspan = this.RootObject.GroupBy.Columns.length
   }
   html += "<td " + this.RootObject.Styles.GetStyleHTML(this.RootObject.Styles.HeaderStyle) + " colspan=" + colspan + " style='cursor:hand' onmousedown=\"" + this.RootObject.Name + ".Events.dragStart(event, 'userimg','" + dragHTML + "'," + this.RootObject.GetEvalObjectString() + ".Columns.Columns[" + this.ID + "])\"  ><table width=100%><tr><td width=100% " + this.RootObject.Styles.GetStyleHTML(this.RootObject.Styles.HeaderStyle) + " >" + this.Header + "</td><td width=10>" + sortImageHTML + "</td></tr></table></td>";
   return html;
  }

 }
 function GetColumnsXML()
 {
   var xml = "" ;
   for(var nX in this.Columns)
   {
       xml += "<Column>" +
                   "<Name>" + this.Columns[nX].ColumnName + "</Name>" +
                   "<DataType>" + this.Columns[nX].DataType + "</DataType>" +
                   "<AllowDBNull>" + this.Columns[nX].AllowDBNull + "</AllowDBNull>" +
                   "<AutoIncrement>" + this.Columns[nX].AutoIncrement + "</AutoIncrement>" +
                   "<AutoIncrementStep>" + this.Columns[nX].AutoIncrementStep + "</AutoIncrementStep>" +
                   "<DefaultValue>" + this.Columns[nX].DefaultValue + "</DefaultValue>" +
                   "<ReadOnly>" + this.Columns[nX].ReadOnly + "</ReadOnly>" +
                   "<Unique>" + this.Columns[nX].Unique + "</Unique>" +
                 "</Column>"; 
   }
   return xml;
 }
 function InsertColumn( _Field, _Key, _Header, _Visible, _Class)
 {
  this.Columns[this.Columns.length] = new Column(this.RootObject, this, this.Columns.length, _Field, _Key, _Header, _Visible, _Class)
  return this.Columns[this.Columns.length-1] ;
 }
 function GetColumnsDisplayInTable()
 {
  var columnsDisplayInTable = new Array() ;
  for(var nX in this.Columns)
  {
   if(this.Columns[nX].Visible==true && this.RootObject.GroupBy.IsGroupByColumn(nX)==false)
   {
    columnsDisplayInTable[columnsDisplayInTable.length] = this.Columns[nX] ;
   }
  }
  return columnsDisplayInTable ;
 }
 function GetVisibleColumns()
 {
  var columnsDisplayInTable = new Array() ;
  for(var nX in this.Columns)
  {
   if(this.Columns[nX].Visible==true)
   {
    columnsDisplayInTable[columnsDisplayInTable.length] = this.Columns[nX] ;
   }
  }
  return columnsDisplayInTable ;
 }
 function Initialize()
 {
 }
 function GetHTMLOutPut(_Table)
 {
  var html = "<td " + this.RootObject.Styles.GetStyleHTML(this.RootObject.Styles.HeaderStyle) + ">&nbsp;</td>" ;
  columns = this.GetColumnsDisplayInTable() ;
  for(var nX in columns)
  {
    html += columns[nX].GetHTMLOutPut(_Table) ;
  }
  return html ;
 }
 function GetHTMLOutPuts()
 {
  var html = "<td class=\"sdxRow2\" align=\"center\">&nbsp;</td>" ;
  columns = this.GetVisibleColumns() ;
  var isFirstColumn = true;
  for(var nX in columns)
  {
    html += columns[nX].GetHTMLOutPutX(isFirstColumn) ;
    isFirstColumn = false ;
  }
  return html ;
 }
}       
 